// detail/detail.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
      isPlayingMusic:true,
      circular:true,
      ditu_id:1,
      htmldata:'',
      Imgs_urls:[],
      src:"",
      srcMic:'',
      isPlay:'',
      duration:'',
      currentTime:'',
      time:'',

  },
  //播放
audioPlay () {
  this.innerAudioContext.play()  
  this.setData({
    isPlay:true
  })
},
// 停止播放
audioPause () {
  this.innerAudioContext.pause()
  this.setData({
  isPlay:false
  })
},
//时间修改
timeChange(){
  var that = this;
  that.setData({
    currentTime:Math.round(that.innerAudioContext.currentTime), //小数转整数
    duration:Math.ceil(that.innerAudioContext.duration), //小数转整数
  //   time:util.secondToTime(Math.ceil(that.innerAudioContext.currentTime))//秒数转分钟与秒
  })
},
//拖动滑块
bindchanging(e){
  var that = this;
  console.log(e)
  //停止播放
  this.innerAudioContext.pause();
  //设置播放时间
  that.innerAudioContext.seek(e.detail.value);
  that.setData({
  //   time:util.secondToTime(that.innerAudioContext.currentTime)//秒数转分钟与秒
  })
 
},
//拖动滑块结束
bindchange(){
  this.innerAudioContext.play();
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
      
      this.setData({'ditu_id':options.ditu_id});
      this.init(options.ditu_id);
      for (let index = 0; index < 4; index++) {
          var tmp = 'https://pan.yatui.com/d/public/xgs/navigator/navigator_banner/'+this.data.ditu_id+'/'+index+'.jpg';
          this.data.Imgs_urls.push(tmp);
      }
      this.setData({Imgs_urls:this.data.Imgs_urls});

  },
  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
      this.innerAudioContext = wx.createInnerAudioContext()
      this.innerAudioContext.src ='https://pan.yatui.com/p/public/xgs/navigator/audio/'+this.data.ditu_id+'.m4a';
      this.innerAudioContext.onTimeUpdate(this.timeChange)
      
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
      this.innerAudioContext.pause()
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
      this.innerAudioContext.pause()
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
      this.innerAudioContext.pause()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
  
  },
  init(ditu_id=0){
      wx.request({
        url: 'https://www.ruoai.cn/xgs/ditu/'+ditu_id,
        method:'get',
        success:(data)=>{
          this.setData({htmldata:data.data})
      }
      });
  },
  upload(){
      wx.chooseMedia({
          count:1,
          mediaType:['image'],
          sourceType:['album','camera'],
          sizeType:'compressed',
          success:function(data){
              let tempFile = data.tempFiles[0].tempFilePath;
              wx.showLoading({
                title: '正在上传',
              });
              setTimeout(function(){
                  wx.hideLoading();
                  wx.showModal({
                    title: '上传成功',
                    content: '感谢您的参与，请等待审核',
                    cancelText:'好的',
                    showCancel:false,
                    confirmText:'好的',
                    complete: (res) => {
                      if (res.cancel) {
                        
                      }
                  
                      if (res.confirm) {

                      }
                    }
                  })
              },1000);
          }
      });
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage(res) {
      var that = this;
      console.log(that.data.htmldata.id);

      return{
          title:that.data.htmldata.title,
          imageUrl:'https://pan.yatui.com/d/public/xgs/navigator/navigator_banner/'+that.data.htmldata.id+'/0.jpg',
      }
  }
  
})